package meta.info

import kotlinx.serialization.Serializable

@Serializable
sealed class MetaInfo {
    abstract var id: String
    abstract var name: String
}

interface InfoState {
    fun checkIp (): String
    fun checkPort (): Int
    fun checkLifespan (): Long
}

@Serializable
data class InfoJson (
    var cloud: MetaInfo,
    var broker: MetaInfo,
    var edges: MutableList<MetaInfo>,
    var meters: MutableList<MetaInfo>,
    var sockets: MutableList<MetaInfo>
)

fun InfoJson.findMeters(nameList: List<String>): List<MetaInfo> {
    val findMeters = mutableListOf<MetaInfo>()
    this.meters.forEach { mit ->
        val ret = nameList.find { mit.name.contains(it + "电表")}
        if (ret != null) findMeters.add(mit)
    }
    return findMeters
}


interface InfoMaster {
    val metaInfo: MetaInfo

    companion object Factory {
        fun instance(metaInfo: MetaInfo): InfoMaster = when (metaInfo) {
            is CloudComputing -> CloudComputingFactory(metaInfo)
            is MessageBroker -> MessageBrokerFactory(metaInfo)
            is EdgeComputing -> EdgeComputingFactory(metaInfo)
            is SmartMeter -> SmartMeterFactory(metaInfo)
            is SmartSocket -> SmartSocketFactory(metaInfo)
        }
    }
}